using UnityEngine;
using System.Collections;

public class Obstacle : MonoBehaviour {
	
	private bool ascended = false;
	private bool animationActive = false;
	private const float animationCycles = Balance.OBSTACLES_HEIGHT;
	private float animationStep = 0.0f;
	private float currentAnimationCycle = 0;

	public void Start ()
	{
		
	}
	
	// Update is called once per frame
	void Update ()
	{
		if(animationActive)
		{
			if(currentAnimationCycle >= animationCycles)
			{
				animationActive = false;
				currentAnimationCycle = 0;
			}
			else
			{
				transform.Translate(new Vector3(0, animationStep * Balance.OBSTACLES_SPEED * Time.deltaTime, 0));
				currentAnimationCycle+= Time.deltaTime * Balance.OBSTACLES_SPEED;
			}
		}
	}
	public void switchState()
	{
		if(!animationActive)
		{
			animationStep = (ascended ? -1.0f : 1.0f);
			animationActive = true;
			ascended = !ascended;
		}
	}
}
